﻿using LianChuDemo.Bll.BaseInfoManagerBll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WenDangOne.DbModel.BaseInfoManager;
using WenDangOne.Lib;
using WenDangOne.ViewModel.BaseInfoManagerView;
using WenDangOne.ViewModel.common;

namespace WenDangOne.Controllers.BaseInfoManager
{
    //[Route("api/[controller]/[action]")]
    //[ApiController]
    [ApiModuleRelation("dibage")]
    public class RoleManagerController : MyBaseController
    {
        private RoleDbBll _roleDbBll;
        public RoleManagerController(RoleDbBll roleDbBll)
        {
            _roleDbBll = roleDbBll;
        }
        [HttpGet]
        public ResultModel<RoleDbView> GetRoleViewById(int roleId)
        {
            try
            {
                var data = _roleDbBll.GetRoleViewById(roleId);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<RoleDbView>(ex);
            }
        }
        [HttpPost]
        public ResultModel<PagerResult<RoleDb>> SearchPage(SearchModel sm)
        {
            try
            {
                var data = _roleDbBll.SearchPage(sm);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<PagerResult<RoleDb>>(ex, null);
            }


        }
        /// <summary>
        /// 角色添加
        /// </summary>
        /// <param name="view"></param>
        /// <returns></returns>
        [HttpPost]
        public ResultModel<int> RoleDbAdd(RoleDbView view)
        {
            try
            {
                var data = _roleDbBll.RoleDbAdd(view);
                if(data==0)
                {
                    return MyFail<int>("添加没有成功！");
                }
                return MyOk(data);
            }
            catch (Exception ex)
            {

                return MyError<int>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> RoleDbUpdate(RoleDbView view)
        {
            try
            {
                var data = _roleDbBll.RoleUpdate(view);
                if(data)
                {
                    return MyOk(data);
                }
                return MyFail<bool>("更新没有成功！");
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        //public PagerResult<RoleDb>SearchPage(SearchModel searchModel)
        //{
            
        //}

    }
}
